package cn.com.homeyoda.aimate.aihealth.views;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import androidx.annotation.NonNull;

import cn.com.homeyoda.aimate.aihealth.R;

/**
 * 居中的dialog
 */
public class CenterDialog extends Dialog {

    SureClickListener mSureClickListener;
    String message = "";
    TextView tvMessage;

    public CenterDialog(Context context) {
        super(context);
    }

    public CenterDialog(Context context, String message, SureClickListener sureClickListener) {
        super(context,R.style.BlackDialog);
        mSureClickListener = sureClickListener;
        this.message = message;

    }

    @Override
    public void setContentView(@NonNull View view) {
        //全屏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        Display display = getWindow().getWindowManager().getDefaultDisplay();
        int width = display.getWidth();
        int height = display.getHeight();
        setContentView(view, new ViewGroup.LayoutParams(width, height));
       // getWindow().setBackgroundDrawableResource(android.R.color.transparent);

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_center);

        getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        tvMessage = findViewById(R.id.tv_message);

        if (!TextUtils.isEmpty(message)) {
            tvMessage.setText(message);
        }

        findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });


        findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (mSureClickListener != null){
                    mSureClickListener.sureClick();
                }
            }
        });
    }


    public interface SureClickListener {
        void sureClick();
    }


}
